#include "../include/threadPool.h"
#include <mysql/mysql.h> 
int mysql_use_select(const char *name,const char *condition1,const char *condition2,char * tempbuf,commandStack_t *stack);
int cd_mysql_select(const char *name,const char *condition1,const char *condition2,char * tempbuf,commandStack_t *stack);
int trans_res(int netfd,const char res[])
{
    /* printf("%s\n",res); */
    int type = 0;
    send(netfd,&type,sizeof(type),0);
    int length = strlen(res)+1;
    send(netfd,&length,sizeof(length),0);
    send(netfd,res,length,0);

    return 0;
}
int get_curpath(commandStack_t *stack,char *path)
{
    int id = stack->num[stack->top];
    char char_id[4];
    sprintf(char_id,"%d",id);
    cd_mysql_select("path","id",char_id,path,stack);
    printf("path's len=%ld\n",strlen(path));
    return 0;
}
int apart_dir(char *path,char **p)
{
    if(strlen(path) == 0)
        return 0;
    int i = 0;
    char *cur = path;
    char *pre = path;
    cur++;
    int alp_num = 1;
    while(*cur != '\0')
    {
        if(*cur == '/')
        {
            strncpy(p[i],pre,alp_num);
            alp_num = 0;
            pre = cur;
            /* printf("p[%d]=%s\n",i,p[i]); */
            i++;
        }
        alp_num++;
        cur++;
    }
    strncpy(p[i],pre,alp_num);
    return i+1;
}

int init(char **p,int size)
{
    for(int i = 0;i < size; i++)
    {
        p[i] = (char *)calloc(1,20);
    }
    return 0;
}

int free_p(char **p,int size)
{
    for(int i = 0; i < size; i++)
        free(p[i]);
    return 0;
}
int mysql_use_select(const char *name,const char *condition1,const char *condition2,char * tempbuf,commandStack_t *stack){
    bzero(tempbuf,strlen(tempbuf));//用来装 查找到的结果的字符串

    MYSQL *mysql= mysql_init(NULL);   //申请空间
    MYSQL *res=mysql_real_connect(mysql,   //链接数据库
                                  "localhost",
                                  "root",
                                  "123",
                                  "test",
                                  0,NULL,0);
    if(res==NULL){       //判断数据库链接
        fprintf(stderr,"%s\n",mysql_error(mysql));
        exit(-1);
    }
    char buf[4096]={0};      //用来存储select命令
    sprintf(buf,"select %s from file  where %s = '%s' and username='%s';",name,condition1,condition2,stack->username );
    /* printf("%s\n",buf); */
    int sret=mysql_query(mysql,buf);
    if(sret==-1){
        return sret;//查表失败
    }
    MYSQL_RES *table= mysql_store_result(mysql);
    if(mysql_num_rows(table)==0){
        return -1;
    }
    char buf1[4096]={0};       //用来存储查找到的数据结果
    for(unsigned int  i=0;i<mysql_num_rows(table);i++){
        MYSQL_ROW row=mysql_fetch_row(table);
        for(unsigned int j=0;j<mysql_num_fields(table);j++){
            strcat(buf1,row[j]);
        }
    strcat(buf1,"");
    }
    /* printf("这里测试一下：%s\n",buf1); */
    strcpy(tempbuf,buf1);//将查找到的数据返回给tempbuf，好让他带回去！
    return 0;
}


int ls_mysql_use_select(const char *name,const char *condition1,const char *condition2,char * tempbuf,commandStack_t *stack){
    bzero(tempbuf,strlen(tempbuf));//用来装 查找到的结果的字符串

    MYSQL *mysql= mysql_init(NULL);   //申请空间
    MYSQL *res=mysql_real_connect(mysql,   //链接数据库
                                  "localhost",
                                  "root",
                                  "123",
                                  "test",
                                  0,NULL,0);
    if(res==NULL){       //判断数据库链接
        fprintf(stderr,"%s\n",mysql_error(mysql));
        exit(-1);
    }
    char buf[4096]={0};      //用来存储select命令
    sprintf(buf,"select %s from file  where %s = '%s'and death_or_not = 0 and username='%s';",name,condition1,condition2,stack->username );
    /* printf("%s\n",buf); */
    int sret=mysql_query(mysql,buf);
    if(sret==-1){
        return sret;//查表失败
    }
    MYSQL_RES *table= mysql_store_result(mysql);
    if(mysql_num_rows(table)==0){
        return -1;
    }
    char buf1[4096]={0};       //用来存储查找到的数据结果
    for(unsigned int  i=0;i<mysql_num_rows(table);i++){
        /* printf("-----------\n"); */
        MYSQL_ROW row=mysql_fetch_row(table);
        for(unsigned int j=0;j<mysql_num_fields(table);j++){
            strcat(buf1,row[j]);
        }
    strcat(buf1," ");
    }
    /* printf("这里测试一下：%s\n",buf1); */
    strcpy(tempbuf,buf1);//将查找到的数据返回给tempbuf，好让他带回去！
    return 0;
}

int mysql_use_update(const char *condition1,const char *condition2,int id,commandStack_t *stack){
    MYSQL *mysql= mysql_init(NULL);   //申请空间
    MYSQL *res=mysql_real_connect(mysql,   //链接数据库
                                  "localhost",
                                  "root",
                                  "123",
                                  "test",
                                  0,NULL,0);
    if(res==NULL){       //判断数据库链接
        fprintf(stderr,"%s\n",mysql_error(mysql));
        exit(-1);
    }
    char buf[4096]={0};      //用来存储select命令
    sprintf(buf,"update  file set %s='%s'  where id = %d and username='%s';",condition1,condition2,id,stack->username );
    mysql_query(mysql,buf);
    printf("update over\n");
    return 0;
}

int cd_mysql_select(const char *name,const char *condition1,const char *condition2,char * tempbuf,commandStack_t *stack){
    bzero(tempbuf,strlen(tempbuf));//用来装 查找到的结果的字符串

    MYSQL *mysql= mysql_init(NULL);   //申请空间
    MYSQL *res=mysql_real_connect(mysql,   //链接数据库
                                  "localhost",
                                  "root",
                                  "123",
                                  "test",
                                  0,NULL,0);
    if(res==NULL){       //判断数据库链接
        fprintf(stderr,"%s\n",mysql_error(mysql));
        exit(-1);
    }
    char buf[4096]={0};      //用来存储select命令
    sprintf(buf,"select %s from file  where %s = %s and death_or_not = 0 and username='%s';",name,condition1,condition2,stack->username );
    /* printf("%s\n",buf); */
    int ret = mysql_query(mysql,buf);
    if(ret == -1)
    { 
        // 查表失败返回
        return -1;
    }
    MYSQL_RES *table= mysql_store_result(mysql);
    char buf1[4096]={0};       //用来存储查找到的数据结果
    for(unsigned int  i=0;i<mysql_num_rows(table);i++){
        /* printf("-----------\n"); */
        MYSQL_ROW row=mysql_fetch_row(table);
        for(unsigned int j=0;j<mysql_num_fields(table);j++){
            strcat(buf1,row[j]);
        }
    strcat(buf1,"");
    }
    /* printf("这里测试一下：%s\n",buf1); */
    strcpy(tempbuf,buf1);//将查找到的数据返回给tempbuf，好让他带回去！
    return 0;
}

int get_part_path(char *path,char *part_path){
    char *p[50]; 
    init(p,50);
    int count=apart_dir(path,p);
    if(count==1&&path[0]=='/'){
        strcpy(part_path,"/");
        free_p(p,count);
        return 1;
    }else if(count==1){
        return 1;
    }
    for(int i=0;i<count-1;i++){
        strcat(part_path,p[i]);
    }
    free_p(p,count);
    return 0;
}

int get_end_dir(char *path,char *end_dir){
    char *p[50];
    init(p,50);
    int count=apart_dir(path,p);
    if(count==1&&path[0]=='/'){
        strcpy(end_dir,p[0]+1);
        return 0;
    }
    strcpy(end_dir,p[count-1]);
    return 0;
}

int compare_table(MYSQL *mysql,char *compare_path,commandStack_t *commandStack){
    MYSQL_RES *table=mysql_store_result(mysql);
    if(table==NULL){
        fprintf(stderr,"%s:%s\n","mysql_store_result",mysql_error(mysql));
        exit(-1);
    }
    for(unsigned long i=0;i<mysql_num_rows(table);i++){
        MYSQL_ROW row=mysql_fetch_row(table);
        char tempbuf[5]={0};
        mysql_use_select("death_or_not","path",row[0],tempbuf,commandStack);
        if(strcmp(row[0],compare_path)==0 && tempbuf[0]=='0'){
            mysql_free_result(table);
            return 1;
        }
    }
    mysql_free_result(table);
    return 0;
} 


int do_ls(int netfd,commandStack_t *stack,char * pathname){
    char p=*pathname;
    char test[40]={0};
    char str[20]={0};
    sprintf(str,"%d",stack->num[stack->top]);
    mysql_use_select("path","id",str,test,stack);
    strcat(str,pathname);
    if(strlen(pathname)==0){
        char p1[1024]={0};//用来暂时存放路径
        char str[20];
        sprintf(str,"%d",stack->num[stack->top]);
        ls_mysql_use_select("filename","parent_id",str,p1,stack);
        trans_res(netfd,p1);  //将数组传送给用户
    } else if(p=='/'){ //判断是否为绝对路径
        char p1[1024]={0};//用来暂时存放路径
        char id[100];
        mysql_use_select("id","path",pathname,id,stack);
        ls_mysql_use_select("filename","parent_id",id,p1,stack);
        trans_res(netfd,p1);
        //完全版需要将printf换成trans_res将字符串传送给客户端

    }else{//相对路径
        char path[100]={0};
        char str[20]={0};
        sprintf(str,"%d",stack->num[stack->top]);
        mysql_use_select("path","id",str,path,stack); // 第一次查找通过当前工作路径的id将路径找出来
        strcat(path,pathname);
        printf("%s\n",path);   //完整的路径已经找出来了 并且放到了path里面
        char id[10];
        mysql_use_select("id","path",path,id,stack);
        char p1[1024]={0};
        ls_mysql_use_select("filename","parent_id",id,p1,stack);
        trans_res(netfd,p1);
    }
    // 完全版本需要进行的修改：将path.num[0]全部换成path.num[top]。
    return 0;
}


int do_pwd(int netfd,commandStack_t *stack,char *pathname){
  // char *p[40];
   // init(p,40);
    //int count=apart_dir(pathname,p);
    if(strlen(pathname)==0){
        char p1[1024]={0};//用来暂时存放路径
        char str[20];
        sprintf(str,"%d",stack->num[stack->top]);
        mysql_use_select("path","id",str,p1,stack);
        trans_res(netfd,p1);
    }else{
        printf("pwd insert error\n");
    }
    // 完全版本需要进行的修改：将path.num[0]全部换成path.num[top]。
    return 0;
}
int do_cd(int netfd,commandStack_t *stack,char *pathname)
{
    commandStack_t temp_stack;
    init_stack(&temp_stack);
    copy_stack(&temp_stack,stack);
    char *dir_set1[20];
    init(dir_set1,20);
    int count1 = apart_dir(pathname,dir_set1);
    if(strcmp(dir_set1[0],"..") == 0)
    {
        if(stack->top > 0)
            pop_stack(stack);
        for(int i=1;i < count1;i++)
        {
            if(strcmp(dir_set1[i],"/..")==0 && stack->size > 0)
            {
                if(stack->top > 0)
                pop_stack(stack);
            }
            else if(strcmp(dir_set1[i],"/..") != 0)
            {
                char path1[100]="'";
                int id;
                char id_buf[10]={0};
                char path[100]={0};
                get_curpath(stack,path);
                if(strlen(path) > 1)
                { // 已经跳转到根目录，不能再连接"/"，否则会出现//dir1
                    strcat(path,dir_set1[i]);
                    strcat(path1,path);
                        
                }
                else{
                    strcat(path1,dir_set1[i]); 
                }
                strcat(path1,"'");
                cd_mysql_select("id","path",path1,id_buf,stack);
                if(strlen(id_buf) == 0)
                {
                    copy_stack(stack,&temp_stack);
                    trans_res(netfd,"该目录不存在\n");
                    return 0;
                }

                id = atoi(id_buf);
                push_stack(stack,id);
            }
        }
        trans_res(netfd,"目录切换成功\n");
        return 0;
    }
    char buf[1024]={0};
    if(pathname[0] == '/')
    {
        char pathname1[100]="'";
        strcat(pathname1,pathname);
        strcat(pathname1,"'");
        cd_mysql_select("id","path",pathname1,buf,stack);
        if(strlen(buf)==0)
        {
            copy_stack(stack,&temp_stack);
            trans_res(netfd,"该目录不存在");
            return 0;
        }
        clear_stack(stack);
        commandStack_t newstack;
        init_stack(&newstack);
        push_stack(&newstack,atoi(buf));
        int id = 0;
        char parent_id[100]={0};
        while(1)
        {
            cd_mysql_select("parent_id","id",buf,parent_id,stack);
            if(strlen(parent_id) == 0)
            {
                copy_stack(stack,&temp_stack);
                trans_res(netfd,"该目录不存在\n");
                return 0;
            }
            id = atoi(parent_id);
            if(id == -1)
            {
                break;
            }
            push_stack(&newstack,id);
            strcpy(buf,parent_id);
        }
        reverse_stack(stack,&newstack);
        trans_res(netfd,"目录切换成功\n");
    }
    else // 相对路径
    {
        if(strlen(pathname) == 0)
        {
            stack->top = 0;
            trans_res(netfd,"目录切换成功\n");
            return 0;
        }
        char path[100]={0};
        char path1[100]="'";
        get_curpath(stack,path);
        if(strcmp(path,"/") !=0 )
        {
            strcat(path,"/");
        }
        strcat(path,pathname);
        strcat(path1,path);
        strcat(path1,"'");
        /* printf("path1=%s\n",path1); */
        cd_mysql_select("id","path",path1,buf,stack);
        /* printf("after use select,buf=%s\n",buf); */
        if(strlen(buf) == 0)
        { 
            copy_stack(stack,&temp_stack);
            //说明在表中没有找到该目录
            trans_res(netfd,"该目录不存在\n");
            return 0;
        }
        char *dir_set[20];
        init(dir_set,20);
        int count = apart_dir(pathname,dir_set);
        printf("count=%d\n",count);
        for(int i=0;i < count;i++)
        {
            
            strcat(path,dir_set[i]);
            cd_mysql_select("id","path",path1,buf,stack);
            if(strlen(buf)==0)
            {
                copy_stack(stack,&temp_stack);
                trans_res(netfd,"该目录不存在\n");
                return 0;
            }
            push_stack(stack,atoi(buf));
        }
        trans_res(netfd,"目录切换成功\n");
        free_p(dir_set,20);
    }   
    return 0;
}

int rmdir_islegal(commandStack_t *commandStack,char *input_path){
    if(strlen(input_path)==0 || (strlen(input_path)==1&&input_path[0]=='/')){
        //send
        printf("路径不合法\n");
        return 0;
    }
    char recvbuf[50]={0};
    char cur_path[1024]={0};
    char cur_id[1024]={0};
    if(input_path[0]!='/'){
        sprintf(cur_id,"%d",commandStack->num[commandStack->top]);
        mysql_use_select("path","id",cur_id,recvbuf,commandStack);
        strcpy(cur_path,recvbuf);
        if(strlen(cur_path)!=1){
            strcat(cur_path,"/");
        }
        strcat(cur_path,input_path);
        input_path=cur_path;
        //测试
        printf("绝对路径为%s\n",input_path);
    }
    bzero(recvbuf,sizeof(recvbuf));
    int ret=mysql_use_select("death_or_not","path",input_path,recvbuf,commandStack); 
    if(ret==-1){
        //send
        printf("路径不合法\n");
        return 0;
    }
    if(strcmp(recvbuf,"1")==0){
        //send
        printf("该路径已删除\n");
        return 0;
    }
    bzero(recvbuf,sizeof(recvbuf));
    mysql_use_select("id","path",input_path,recvbuf,commandStack); 
    char id[1024]={0};
    strcpy(id,recvbuf);
    bzero(recvbuf,sizeof(recvbuf));
    printf("id=%s\n",id);
    ret=mysql_use_select("id","parent_id",id,recvbuf,commandStack);
    if(ret!=-1){
        //send
        printf("目录非空\n");
        return 0;
    }
    bzero(recvbuf,sizeof(recvbuf));
    mysql_use_select("type","path",input_path,recvbuf,commandStack);
    if(strcmp(recvbuf,"f")==0){
        //send
        printf("不能删除文件\n");
        return 0;
    }
    printf("路径合法\n");
    return 1;
}

int do_rmdir(int netfd,commandStack_t *stack,char *pathname){
    //判断合法性！
    int res=rmdir_islegal(stack,pathname);
    if(res==0){
        trans_res(netfd,"路径不合法\n");
        return 0;
    }
    char p=*pathname;
    if(p=='/'){
    char path[100]={0};
    strcpy(path,pathname);
    char id[10];
    mysql_use_select("id","path",path,id,stack);
    mysql_use_update("death_or_not","1",atoi(id),stack);
    trans_res(netfd,"目录删除成功\n");
    }else{
    char path[100]={0};
    char str[20]={0};
    sprintf(str,"%d",stack->num[stack->top]);
    mysql_use_select("path","id",str,path,stack); // 第一次查找通过当前工作路径的id将路径找出来
    if(strlen(path)!=1){
        strcat(path,"/");
    }
    strcat(path,pathname);
    printf("%s\n",path);   //完整的路径已经找出来了 并且放到了path里面
    char id[10];
    mysql_use_select("id","path",path,id,stack);
    mysql_use_update("death_or_not","1",atoi(id),stack);

    trans_res(netfd,"目录删除成功\n");
    }
    return 0;
}

int mkdir_islegal(commandStack_t *commandStack,char *path){
    MYSQL *mysql=mysql_init(NULL);
    MYSQL *res=mysql_real_connect(mysql,"localhost","root","123","test",0,NULL,0);
    if(res==NULL){       //判断数据库链接
        fprintf(stderr,"%s\n",mysql_error(mysql));
        exit(-1);
    }
    if(strlen(path)==0 ||(path[0]=='/'&&strlen(path)==1)){
        mysql_close(mysql);
        return 0;
    }
    char part_path[1024]={0};
    int ret=get_part_path(path,part_path);
    if(ret==1){
        mysql_close(mysql);
        return 1;
    }
    if(path[0]=='/'){
        char sql[4096]={0};
        sprintf(sql,"select path from file where username='%s';",commandStack->username);
        int qres=mysql_query(mysql,sql);
        if(qres!=0){
            fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(mysql));
            exit(-1);
        }
        if(compare_table(mysql,part_path,commandStack)){
            mysql_close(mysql);
            return 1;
        }
        return 0;
    }else{
        char sql[4096]={0};
        sprintf(sql,"select path from file where id='%d';",commandStack->num[commandStack->top]);
        int qres=mysql_query(mysql,sql);
        if(qres!=0){
            fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(mysql));
            mysql_close(mysql);
            exit(-1);
        }
        MYSQL_RES *table=mysql_store_result(mysql);
        MYSQL_ROW row=mysql_fetch_row(table);
        char new_path[1024]={0};
        strcpy(new_path,row[0]); 
        if(strcmp(row[0],"/")){
            strcat(new_path,"/");
        }
        strcat(new_path,part_path);
        mysql_free_result(table);
        sprintf(sql,"select path from file where username='%s';",commandStack->username);

        qres=mysql_query(mysql,sql);
        if(qres!=0){
            fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(mysql));
            mysql_close(mysql);
            exit(-1);
        }
        if(compare_table(mysql,new_path,commandStack)){
            mysql_close(mysql);
            return 1;
        }
        mysql_close(mysql);
        return 0;
    }
}

int do_mkdir(int netfd,commandStack_t *commandStack,char *path){
    if(mkdir_islegal(commandStack,path)){
        char end_dir[100]={0};
        char part_path[100]={0};
        get_end_dir(path,end_dir);
        get_part_path(path,part_path);
        char *p_end_dir=NULL;
        if(end_dir[0]=='/'){
            p_end_dir=end_dir+1;
        }else{
            p_end_dir=end_dir;
        }
        char fin_path[1024]={0};
        if(path[0]=='/'){
            strcpy(fin_path,path);
        }else{
            char buf2[50]={0};
            sprintf(buf2,"%d",commandStack->num[commandStack->top]);
            char tempbuf1[1024]={0};
            mysql_use_select("path","id",buf2,tempbuf1,commandStack);
            strcpy(fin_path,tempbuf1);
            if(strlen(tempbuf1)!=1){
               strcat(fin_path,"/"); 
            }
            strcat(fin_path,path);
        }
        char tempbuf1[128]={0};
        int ret=mysql_use_select("id","path",fin_path,tempbuf1,commandStack);
        if(ret!=-1){
            int id=atoi(tempbuf1);
            bzero(tempbuf1,sizeof(tempbuf1));
            mysql_use_select("death_or_not","path",fin_path,tempbuf1,commandStack);
            if(tempbuf1[0]=='0'){
                printf("路径不合法\n");
                trans_res(netfd,"路径不合法\n");
                //send
                return -1;
            }else{
                mysql_use_update("death_or_not","0",id,commandStack);
                trans_res(netfd,"目录创建成功\n");
                return 0;
            }
        }
        printf("路径合法\n");
        char sql_parent_id[50]={0};
        char fin_part_path[100]={0};
        get_part_path(fin_path,fin_part_path);
        mysql_use_select("id","path",fin_part_path,sql_parent_id,commandStack);
        char sql[4096]={0};
        MYSQL *mysql=mysql_init(NULL);
        MYSQL *res=mysql_real_connect(mysql,"localhost","root","123","test",0,NULL,0);
        if(res==NULL){       //判断数据库链接
            fprintf(stderr,"%s\n",mysql_error(mysql));
            exit(-1);
        }
        sprintf(sql,"insert into file (filename,username,parent_id,path,type,death_or_not) values ('%s','%s','%s','%s','d','0');",p_end_dir,commandStack->username,sql_parent_id,fin_path);
        int qres=mysql_query(mysql,sql);
        if(qres!=0){
            fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(mysql));
            exit(-1);
        }
        printf("mkdir success\n");
        trans_res(netfd,"目录创建成功\n");
    }else{
        printf("路径不合法\n");
        trans_res(netfd,"路径不合法\n");
        //send
        return -1;
    }
    return 0;
}


/* int  main(int argc,char * argv[]){ */
/*     commandStack_t *stack; */
/*     init_stack(stack); */
/*     stack->bottom=0; */
/*     stack->top=0; */
/*     stack->num[0]=1; */
/*     strcpy(stack->username,"lisi"); */
/*     printf("%s\n",stack->username); */
/*     do_ls(12,stack,"dir1/"); */
/*     //do_pwd(12,stack,""); */
/*     //do_rmdir(12,stack,"/dir1/"); */
/*     stack->top=2; */
/*     stack->num[stack->top]=2; */
/*     return 0; */
/* } */
/* int  main(int argc,char * argv[]){ */
/*     commandStack_t stack; */
/*     init_stack(&stack); */
/*     push_stack(&stack,1); */
/*     push_stack(&stack,4); */
/*     push_stack(&stack,7); */

/*     strcpy(stack.username,"zhangsan"); */
/*     char path[100]={0}; */
/*     get_curpath(&stack,path); */
/*     /1* printf("after get curpath:path=%s,before cd\n",path); *1/ */
    
/*     char pathname[100]="../../dir3"; */
/*     /1* char command[10]; *1/ */
/*     /1* scanf("%s %s",command,pathname); *1/ */
/*     do_cd(1,&stack,pathname); */
    
/*     get_curpath(&stack,path); */
/*     printf("path=%s\n",path); */
/*     get_curpath(&stack,path); */
/*     printf("%s\n",path); */ 
/*     return 0; */
/* } */
/* int  main(int argc,char * argv[]){ */
/*     commandStack_t stack; */
/*     stack.bottom=0; */
/*     stack.top=0; */
/*     stack.num[0]=2; */
/*     do_ls(12,stack,""); */
/*     do_pwd(12,stack,""); */
/*     return 0; */
/* } */

//int main(int argc, char *argv[]){
//    commandStack_t commandStack;
//    commandStack.num[0]=1;
//    commandStack.num[1]=2;
//    commandStack.num[2]=3;
//    commandStack.num[3]=4;
//    commandStack.num[4]=5;
//    commandStack.top=1;
//    commandStack.username=(char*)calloc(20,sizeof(char));
//    strcpy(commandStack.username,"ta");
//    char path1[100]="/";
//    char path3[100]="/dir1";
//    char path4[100]="/dir3";
//    char path5[100]="dir1";
//    char path6[100]="dir4";
//    char path7[100]="dir6";//top=3
//    char path8[100]="dir2";//top=1
//    char path9[100]="/dir1/dir5/dir11";
//    //MYSQL *mysql=mysql_init(NULL);
//    //MYSQL *res=mysql_real_connect(mysql,"localhost","root","1234","event_test",0,NULL,0);
//    //if(islegal(&commandStack,path8,MKDIR)){
//    //    printf("该路径合法\n");
//    //}else{
//    //    printf("该路径不合法\n");
//    //}
//    do_mkdir(4000,&commandStack,path9);
//    return 0;
//}

